/*
 * CodeSaveCommand.java
 *
 * Created on 2006년 3월 29일 (수), 오후 4:11
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.qbooks.cms.admin;

import java.io.File;
import java.util.*;





import javax.servlet.*;
import javax.servlet.http.*;

import com.zll.framework.conf.Configuration;
import com.zll.framework.model.HashBox;
import com.zll.framework.servlet.Command;
import com.qbooks.common.CommonUtil;





/**
 *
 * @author eastar
 */
public class AppHistorySaveCommand implements Command
{

    public String execute(HttpServletRequest  request, HttpServletResponse response)
    throws Exception
    {
    	HashBox box = new HashBox(request);
    	
    	String storage	= Configuration.get("dir.storage");
		String apkUrl	= Configuration.getHomePath() + File.separator + "home" + File.separator + "apps" + File.separator + "apk" + File.separator + box.get("app_id");
    	
		////////////////////////// 웹 경로에 저장 ////////////////////////
		File f = box.getFile("download_url");
		if (f != null) {
			File dir = new File(apkUrl);
			if (!dir.exists()) {
				dir.mkdir();
			}
			File newFile = new File(dir.getPath() + File.separator + f.getName());
			f.renameTo(newFile);
			box.put("download_url", "http://" + Configuration.get("domain") + "/home/apps/apk/"+ box.get("app_id") + "/" + newFile.getName());
		}
		

		AdminDAO dao 		= new AdminDAO();

		dao.saveAppHistory(box);


		HashMap result		= new HashMap();
		result.put("result", 	"true");
		result.put("target",	box.target);
		if ("U".equals(box.get("job_type"))) {
			result.put("action",	"/cms/admin/appHistoryDetail.jsp?app_id=" + box.get("app_id") + "&history_seq="+box.get("history_seq"));
		} else {
			result.put("action",	"/cms/admin/appDetail.jsp?app_id=" + box.get("app_id"));
		}

    	request.setAttribute("result", result);


    	return "/common/move_view.jsp";
    }
}
